Skip to content

fix(codegen)!: name each generated enum value once - #1799

Merged
bokelley merged 1 commit into
nextfrom
claude/issue-1782-enum-aliases
Nov 2, 2026
Merged

bokelley merged 1 commit into
nextfrom
claude/issue-1782-enum-aliases

Conversation

@bokelley

@bokelley bokelley commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #1782. datamodel-code-generator merges an anyOf arm's narrower enum into the root enum without deduplicating (postal-country-system.json arm 0 narrows system to ['zip', 'zip_plus_four']), so the generated StrEnum carried zip = 'zip' and zip_1 = 'zip': 19 enums on 10.0.0b4, 44 members across 11 modules on 3.3.0-beta.3.

  • New post-generation pass dedupe_enum_member_values: keeps the first member for each value and removes the repeats; registered in the fix list and the effect manifest.
  • tests/test_generated_enums_have_no_aliases.py holds the whole generated tree to one member per value (the issue's reproduction as a test), pins System.zip directly, and unit-tests the pass for idempotence and for leaving non-enum classes alone.
  • MIGRATION_v9_to_v10.md row added.

BREAKING CHANGE: the _1 alias members of generated enums (System.zip_1, Field17.ad_request_url_1, ...) are removed. Use the real member (System.zip); System("zip") and member.value are unchanged.

Test plan

  • make lint ✓; make validate-generated, make typecheck-all and the CI runner are running locally; CI is authoritative.

🤖 Generated with Claude Code

@aao-secretariat

Copy link
Copy Markdown

Ladon cannot review this PR until merge conflicts are resolved.

datamodel-code-generator merges an anyOf arm's narrower enum into the root
enum without deduplicating, so postal_country_system.System carried
zip = 'zip' and zip_1 = 'zip' (19 enums on 10.0.0b4; #1782). Python makes the
second member an alias of the first, so nothing broke at runtime, but
__members__, autocomplete and member.name offered names that are not AdCP
values.

post_generate_fixes.dedupe_enum_member_values keeps the first member for each
value and removes the repeats (44 members across 11 modules on 3.3.0-beta.3).
tests/test_generated_enums_have_no_aliases.py holds the whole generated tree
to one member per value.

BREAKING CHANGE: the _1 alias members of generated enums (System.zip_1,
Field17.ad_request_url_1, ...) are removed. Use the real member
(System.zip); System("zip") and member.value are unchanged.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@bokelley
bokelley force-pushed the claude/issue-1782-enum-aliases branch from f7d34b1 to ca6c8bd Compare November 2, 2026 00:17

@aao-secretariat aao-secretariat Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ladon verdict: Approve

Approve — clean, tightly-scoped codegen fix.

The PR adds a post-generate pass dedupe_enum_member_values that drops the <name>_1 alias enum members datamodel-code-generator emits when an anyOf arm repeats an enum value. The implementation is AST-based, first-declared-member-wins, uses reverse-order deletion, and ships with idempotence and whole-tree regression tests.

Semver signal is correct: shipped as fix(codegen)!: with a BREAKING CHANGE footer and a migration row. The change is Python-surface-only (.value and System("zip") unchanged), so there is no wire change. The generated domains/** diffs are regeneration output paired with the script + manifest change — the legitimate pathway, not a hand-edit.

No blocking or Medium findings were reported. One non-blocking note: the PR body lists make validate-generated as still running rather than confirmed green; CI is authoritative on whether the committed generated diff reproduces.

Gate check: high_risk false, gated_paths false, no no-auto-approve team match, no prior decision. No findings at any severity — rows 1–8 do not fire, so row 9 applies.

@bokelley
bokelley merged commit 0357253 into next Nov 2, 2026
41 checks passed
@bokelley
bokelley deleted the claude/issue-1782-enum-aliases branch November 2, 2026 02:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant